<?php
namespace app\controllers\admin;

use app\controllers\common\ExaminationController;
use app\models\StudentPaper;
use app\service\UrlService;
use yii;
use app\models\KsSurvey;
use app\models\PaperScoreInfo;
use yii\helpers\BaseJson;

class PersonalController extends ExaminationController
{
    // 个人信息
    public function actionIndex(){
        $personalinfo = $this->current_user;

        return $this->render(UrlService::BuildUrl('/admin/personal/index'),['info'=>$personalinfo]);
    }

    //往期考试
    public function actionPast(){
        $uid = $this->current_user['id'];
        if(!$uid){return $this->render('/error/error',['message'=>'无效参数']);}
        $info  = $this->getpaper($uid);
//        die;
        $info = BaseJson::decode($info);

        if($info['code'] == 404 ){return $this->render('/error/error',['message'=>':(没有考试记录']); }
        return $this->render(UrlService::BuildUrl('admin/personal/info'),['info'=>$info['data']]);
    }

    public function actionPaperinfo($studentpaperid)
    {
        //分数
        $sp = PaperScoreInfo::findOne(['sptableid'=>$studentpaperid]);
        //查询答题卡，查询原题
        $datika = StudentPaper::findOne(['id'=>$sp->sptableid]);
        //答题卡内容
        $papercontent = BaseJson::decode($datika->paper_content);
//        var_dump($papercontent);

        $ksinfo = KsSurvey::findOne(['id'=>$datika->paperid]);
        $emaminationinfo = BaseJson::decode($ksinfo->exampinfo);

        foreach($emaminationinfo as $index => $item){
            foreach($item as $k => $v){
                $emaminationinfo[$index][$k]['ss'] = $papercontent[$index][$k];
            }
        }

        return $this->render('/admin/personal/examinfo',[
            'classid_papers'=>$papercontent, //考试的答题卷
            'examinationInfo'=>$emaminationinfo,#试卷内容
            'selscore'=>$ksinfo->selscore,//选择题每道多少分
            'chescore'=>$ksinfo->chescore,//多选题每道分数
            'judscore'=>$ksinfo->judscore,//每道判断题分数
            'cmpscore'=>$ksinfo->cmpscore,#每道填空题分数
            'bosscore'=>$ksinfo->bosscore,#每道大题分数
            'timeout'=>$ksinfo->timeout,#考试时间
            'examname'=>$ksinfo->examname,#试卷名
            'scoreinfo'=>$sp,
            'controlleroptions'=>['A','B','C','D','E','F','G','H'],
        ]);



    }
    /*
     * 查询某个学号的所有考试记录
     * */
    private function getpaper($uid){
        if(!is_numeric($uid))return 500;
        $all = PaperScoreInfo::find()->where(['sid'=>$uid])->asArray()->all();
        if(empty($all)){return $this->returnJSON([],'is null',404);}
        return $this->returnJSON($all,'success',200);
    }
}

?>